//
//  CNBaseTableViewController.swift
//  Ccweibo
//
//  Created by 陈锦聪 on 16/3/20.
//  Copyright © 2016年 Coco. All rights reserved.
//

import UIKit

class CNBaseTableViewController: UITableViewController {
    
    private lazy var visitorView: CNVisitorView = CNVisitorView()

    var userLogin = CNUserAccountViewModel.sharedInstance.isLogin
    
    override func viewDidLoad() {
        super.viewDidLoad()

    }

    override func loadView() {
        userLogin ? super.loadView() : setupVisitorView()
    }

    private func setupVisitorView() {
        
        view = visitorView
        
        visitorView.delegate = self
        
        if self is CNHomeViewController {
            
            visitorView.startRotationAnimation()
            
        } else if self is CNMessageViewController {
            
            visitorView.setupVisitorInfo("visitordiscover_image_message", message: "登录后，别人评论你的微博，发给你的消息，都会在这里收到通知")
            
        } else if self is CNDiscoverViewController {
            
            visitorView.setupVisitorInfo("visitordiscover_image_message", message: "登录后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过")
            
        } else if self is CNProfileViewController {
            
            visitorView.setupVisitorInfo("visitordiscover_image_profile", message: "登录后，你的微博、相册、个人资料会显示在这里，展示给别人")
        }
        // 添加导航栏按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorViewDidClickRegisterButton")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登陆", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorViewDidClickLoginButton")
    }
    
}
// MARK: - CNVisitorViewDelegate
extension CNBaseTableViewController: CNVisitorViewDelegate {
    
    func visitorViewDidClickRegisterButton() {
        print(__FUNCTION__)
    }
    func visitorViewDidClickLoginButton() {
        
        let oauthVC = CNOauthViewController();
        
        presentViewController(UINavigationController(rootViewController: oauthVC), animated: true, completion: nil)
    }
}
